/**
 * 找回密码
 */
Ext.define('Admin.ResetPwdWin', {
    extend: 'Ext.window.Window',
    height: 260,
    maximizable: true,
    width: 400,
    layout: 'fit',
    resizable: false,
    buttonsAlign: "center",
    modal: true,
    initComponent: function () {
        var win = this;
        Ext.apply(this, {
            buttons: [{
                text: "提交",
                scope: this,
                handler: function (o, e, t) {

//                    var emailForm = this.getComponent('emailForm').getForm();
//
//                    var pwd = emailForm.findField('password').getId();
//                    var repwd = emailForm.findField('password').getId();
//                    if(!pwd || !repwd || pwd.length < 1 || repwd.length < 1)
//                    {
//                        UI.showErrorMsg("【温馨提示】", "密码输入长度不一样或内容为空，请重新输入！！！");
//                        return ;
//                    }

                    emailForm.submit({
                        clientValidation: true,
                        success: function (form, action) {
                            if (action.result.success) {
                                setTimeout(function () {
                                    win.close();
                                    window.location.href = action.result.url;
                                }, 5000);
                                UI.showInfoMsg("【温馨提示】", action.result.msg);
                            } else {
                                UI.showInfoMsg("【温馨提示】", action.result.error);
                            }

                        },
                        failure: ajax_form_failed
                    });
                }
            }]
        });

        var emailForm = Ext.create('Ext.form.Panel', {
            layout: 'anchor',
            margin: "20 25 20 25",
            border: false,
            bodyStyle: "padding-top:40px",
            id: 'emailForm',
            url: F.url("/account/getPwd/udpPwd.do"),
            defaultType: 'textfield',
            defaults: {
                anchor: '100%'
            },
            items: [{
                xtype: 'hiddenfield',
                name: 'tk'
            }, {
                fieldLabel: '新密码',
                name: 'password',
                allowBlank: false,
                inputType: 'password',
                vtype: 'alphanum',
                minLength: 6,
                maxLength: 32,
                minLengthText: '密码最短为{0}位',
                maxLengthText: '密码最长不可超过 {0}位'
            }, {
                fieldLabel: '再次输入',
                name: 'repassword',
                allowBlank: false,
                inputType: 'password',
                vtype: 'alphanum',
                minLength: 6,
                maxLength: 32,
                minLengthText: '密码最短为{0}位',
                maxLengthText: '密码最长不可超过 {0}位'
            }],
            listeners: {
                beforeaction: function (form, action) {
                    if (form.findField('password').getValue() !== form.findField('repassword').getValue() || form.findField('password').getValue().length < 1) {
                        UI.showErrorMsg("【温馨提示】", "两次密码输入不一致");
                        return false;
                    }
                }
            }
        });

        this.items = [emailForm];
        this.callParent();

        var tkField = this.getComponent('emailForm').getForm().findField('tk');
        tkField.setValue(this.tk);
        tkField.setReadOnly(true);
    }
});
